var sns = {}
sns.toUpdate = function(url, param, boxname,id){
	var idx = sns.getCheckbox(boxname);
	if(idx == false){
		alert('please choose at least one');
		return;
	}
	if(idx.indexOf(",") != -1){
		alert('Only can choose one');
		return;
	}
	param[id]=idx;
	var suffix = "?";
	var tag = true;
	for(var index in param){
		if (tag){
			suffix = suffix + index + "=" + param[index];
			tag = false;
		}else{
			suffix = suffix + "&" + index + "=" + param[index];
		}
	}

	location.href=url + suffix;
}
sns.toRemove = function(url, param, boxname,id){
	var idx = sns.getCheckbox(boxname);
	if(idx == false){
		alert('please choose at least one');
		return;
	}

	param[id]=idx;
	var suffix = "?";
	var tag = true;
	for(var index in param){
		if (tag){
			suffix = suffix + index + "=" + param[index];
			tag = false;
		}else{
			suffix = suffix + "&" + index + "=" + param[index];
		}
	}
	location.href=url + suffix;
}
sns.dynaRemove = function(url, param, boxname,id, idpre){
	var idx = sns.getCheckbox(boxname);
	if(idx == false){
		alert('please choose at least one');
		return;
	}

	param[id]=idx;
	var suffix = "";
	var tag = true;
	for(var index in param){
		if (tag){
			suffix = suffix + index + "=" + param[index];
			tag = false;
		}else{
			suffix = suffix + "&" + index + "=" + param[index];
		}
	}
	$.ajax({
		url:url, 
		type:"POST", 
		data:suffix, 
		dataType:"html", 
		timeout:20000, 
		error:function () {
			msg_show("System Error", "Can't connect with server");
		}, 
		success:function (html) {
			var ids = idx.split(",");
			for(var i=0;i<ids.length;i++){
				if($("#"+idpre+ids[i])){
					$("#"+idpre+ids[i]).remove();
				}
			}
			if(rollback){
				rollback();
			}
		}
	});
}
sns.getCheckbox = function(boxname){
	var idx="";
	var checkboxFilter="input[name='"+boxname+"']";
	$(checkboxFilter).each(function(){
	    if($(this).attr("checked")) {
	    idx = idx + $(this).val() + "," ;
	   }
	});
	return idx.length>0?idx.substring(0, idx.length - 1):false;
}

var tkra = {};
tkra.appendAjax = function(urlpath, data, appendElementId,rollback){
	$.ajax({
		url:urlpath, 
		type:"POST", 
		data:data, 
		dataType:"html", 
		timeout:20000, 
		error:function () {
			msg_show("System Error", "Can't connect with server");
		}, 
		success:function (html) {
			$(appendElementId).append(html);
			if(rollback){
				rollback();
			}
		}
	});
}
tkra.htmlAjax = function(urlpath, data, appendElementId,rollback){
	$.ajax({
		url:urlpath, 
		type:"POST", 
		data:data, 
		dataType:"html", 
		timeout:20000, 
		success:function (html) {
			$(appendElementId).html(html);
			if(rollback){
				rollback();
			}
		}
	});
}
tkra.replaceAjax = function(urlpath, data, appendElementId,rollback){
	$.ajax({
		url:urlpath, 
		type:"POST", 
		data:data, 
		dataType:"html", 
		timeout:20000, 
		success:function (html) {
			$(appendElementId).replaceWith(html);
			if(rollback){
				rollback();
			}
		}
	});
}
tkra.openNewWindowAjax = function(urlpath, data, width,height,title,rollback){
	$.ajax({
		url:urlpath, 
		type:"POST", 
		data:data, 
		dataType:"html", 
		timeout:20000, 
		success:function (html) {
			msg_show(title,html,width,height);
			if(rollback){
				rollback();
			}
		}
	});
}
function copyToClipBoard(href){
    var txt="";   
    if(href){
    	txt = "http://www.isansui.com" +href;
    }else{
    	txt = windows.location.href;
    }
    if(window.clipboardData){
        window.clipboardData.clearData();
        window.clipboardData.setData("Text",txt);
    }
    else if(navigator.userAgent.indexOf("Opera")!=-1){
        window.location=txt;
    }
    else if(window.netscape){
        try{
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch(e){
            alert("您的firefox安全限制限制您进行剪贴板操作，请打开'about:config'将 signed.applets.codebase_principal_support'设置为true'之后重试，相对路径为firefox根目录 /greprefs/all.js");
            return;
        }
        var clip=Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if(!clip) return;
        var trans=Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if(!trans)return;
        trans.addDataFlavor('text/unicode');
        var str=new Object();
        var len=new Object();
        var str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext=txt;str.data=copytext;
        trans.setTransferData("text/unicode",str,copytext.length*2);
        var clipid=Components.interfaces.nsIClipboard;
        if(!clip)return false;
        clip.setData(trans,null,clipid.kGlobalClipboard);
    }  
}
